<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>dateRangeGenerator</title>
</head>

<body>
    <script>
        const dateRangeGenerator = function* (start, end, step = 1) {
            let d = start;
            while (d <= end) {
                yield new Date(d);
                d.setDate(d.getDate() + step);
            }
        };
        document.writeln([...dateRangeGenerator(new Date('2021-06-01'), new Date('2021-06-04'))].join(','))
    </script>
</body>

</html>